package com.yqg.education.common.config;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ParameterType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

//配置Swagger  http://localhost:9100/api/swagger-ui/index.html
@Configuration
@EnableOpenApi
public class MySwaggerConfig{
    //api接口包扫描路径
    public static final String ReceptionController = "com.yqg.education.controller";
     //    public static final String VERSION = "1.0.0";
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("自动化生产线监控与管理平台")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(ReceptionController))
                .paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build()
                .globalRequestParameters(Lists.newArrayList(
                        new RequestParameterBuilder()
                                .name("token")
                                .description("输入:“swagger_pass_token”")
                                .in(ParameterType.HEADER)
                                .build()
                ));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("自动化生产线监控与管理平台") //设置文档的标题
                .description("自动化生产线监控与管理平台 API 接口文档") // 设置文档的描述
//                .version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
                .termsOfServiceUrl("") // 设置文档的License信息->1.3 License information
                .build();
    }
}
